<?php
$cs=Yii::app()->clientScript; 
$cs->registerScriptFile('./js/freezePane.js');
$cs->registerScript('transport_stat_excel',<<<END
$("#excel").click(
function(){
	if($("#s_date").val()=='') {alert("请输入业务时间!");return;}
	var act=$("form").attr('action');
	$("form").attr('action',act+'&excel=1');
	$("form").attr('target','_blank');
	$("form").submit();
	$("form").attr('action',act);
	$("form").attr('target','');
}
);

$("#freezePane_cb").click(freezePane);

END
);
?>
<h2>运输月统计表</h2>
<?php echo CHtml::beginForm();?>
<table  style="margin: 0 auto;"  width="860px">
<tr><td>
	业务类型：<?php echo CHtml::dropDownList('b_type', isset($_POST['b_type'])?$_POST['b_type']:'', array('0'=>'运输','1'=>'仓储','2'=>'装卸'));?>&nbsp;&nbsp;&nbsp;&nbsp;
	业务时间:<input type="text" id="s_date" name="s_date" size="7" value="<?php echo isset($_POST['s_date'])?$_POST['s_date']:'';?>"/>&nbsp;&nbsp;&nbsp;&nbsp;
	<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'s_date','ifFormat'=>'%Y-%m'));?>
	<input type="submit" value="搜索"/>&nbsp;&nbsp;&nbsp;&nbsp;<input id="excel" type="button" value="输出excel文件"/>
	&nbsp;&nbsp;&nbsp;&nbsp;<input id="freezePane_cb" class="#freezePane" type="checkbox"><label for="freezePane_cb">冻结标题</label>
</td></tr></table>
<?php echo CHtml::endForm();?>
<table id="freezePane" class="dataGrid" width="860px">
  <thead>
  <tr>
    <th width="200">客户</th>
    <th width="100">车次</th>
    <th width="80">吨位</th>
    <th width="80">应收</th>
    <th width="80">应付</th>
    <th width="80">差价</th>
    <th width="80">液奶补损</th>
    <th width="80">差价率</th>
    <th width="80">差价/总差价</th>
  </tr>
  </thead>
  <tbody>
<?php if(isset($models)):?>
<?php foreach($models as $n=>$model):?>
<?php if($model->carrier_type==0) break;?>
  <tr class="<?php echo $n%2?'odd':'even';?>">
    <td><?php echo CHtml::encode($model->customer_name); ?></td>
    <td><?php echo CHtml::encode($model->truck_times); ?></td>
    <td><?php echo CHtml::encode($model->tonnage); ?></td>
    <td><?php echo CHtml::encode($model->receivable_amount); ?></td>
    <td><?php echo CHtml::encode($model->payable_amount); ?></td>
    <td><?php echo CHtml::encode($model->disparity); ?></td>
    <td><?php echo CHtml::encode($model->loss_amount); ?></td>
    <td><?php echo CHtml::encode($model->disparity_ratio); ?></td>
    <td><?php echo CHtml::encode($sum_models[1-$model->carrier_type]->disparity>0?$model->disparity/$sum_models[1-$model->carrier_type]->disparity*100:0,'%.2f%%');?></td>
  </tr>
<?php endforeach; ?>
<?php if(count($models)>0&&$models[0]->carrier_type==1):?>
 <tr style="background:#c6cdf9;">
    <td><?php echo '第三方小计' ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->truck_times); ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->tonnage); ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->receivable_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->payable_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->disparity); ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->loss_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[0]->disparity_ratio); ?></td>
    <td><?php echo $sum_models[0]->disparity==0?'0%':'100%'?></td>
  </tr>
<?php endif;?>
<?php foreach($models as $n=>$model): ?>
<?php if($model->carrier_type==1) continue;?>
  <tr class="<?php echo $n%2?'odd':'even';?>">
    <td><?php echo CHtml::encode($model->customer_name); ?></td>
    <td><?php echo CHtml::encode($model->truck_times); ?></td>
    <td><?php echo CHtml::encode($model->tonnage); ?></td>
    <td><?php echo CHtml::encode($model->receivable_amount); ?></td>
    <td><?php echo CHtml::encode($model->payable_amount); ?></td>
    <td><?php echo CHtml::encode($model->disparity); ?></td>
    <td><?php echo CHtml::encode($model->loss_amount); ?></td>
    <td><?php echo CHtml::encode($model->disparity_ratio); ?></td>
    <td><?php echo CHtml::encode($sum_models[1-$model->carrier_type]->disparity>0?$model->disparity/$sum_models[1-$model->carrier_type]->disparity*100:0,'%.2f%%');?></td>
  </tr>
<?php endforeach; ?>
<?php if(count($models)>0&&$models[count($models)-1]->carrier_type==0):?>
 <tr style="background:#c6cdf9;">
    <td><?php echo '自有车小计' ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->truck_times); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->tonnage); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->receivable_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->payable_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->disparity); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->loss_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->disparity_ratio); ?></td>
    <td><?php echo $sum_models[1]->disparity==0?'0%':'100%'?></td>
  </tr>
<?php endif;?>
 <tr style="background:#c6cdf9;">
    <td><?php echo '总计' ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->truck_times+$sum_models[0]->truck_times); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->tonnage+$sum_models[0]->tonnage); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->receivable_amount+$sum_models[0]->receivable_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->payable_amount+$sum_models[0]->payable_amount); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->disparity+$sum_models[0]->disparity); ?></td>
    <td><?php echo CHtml::encode($sum_models[1]->loss_amount+$sum_models[0]->loss_amount); ?></td>
    <td><?php echo CHtml::encode(($sum_models[1]->disparity+$sum_models[0]->disparity)/($sum_models[1]->receivable_amount+$sum_models[0]->receivable_amount)*100,'%.2f%%');?></td>
    <td><?php echo '100%'?></td>
  </tr>
<?php endif;?>
  </tbody>
</table>
<br/>
<?php if(!isset($models)):?>
 <h4 id="no_record" style="text-align:center;">暂时没有符合要求的记录!</h4>
<?php endif;?>